#include<iostream>
#include "threadPool.h"
using namespace std;
#include <memory>
#include <string>
#include <future>
#include <vector>
#include <unistd.h>

std::string test(std::string str)
{
    return "hello" + str;
}

int test2(int a, int b)
{
    return a + b;
}

int main(void)
{
    CThreadPoll pool(1);

    int threadNum = pool.getThreadNum();
    std::cout << "threadNum: " << threadNum << std::endl;

    auto task = std::make_shared<std::packaged_task<std::string()>>(std::bind(test, "world"));
    std::future<std::string> res = task->get_future();
    pool.enqueue([task = std::move(task)] { (*task)(); }, threadNum -1);

    auto task2 = std::make_shared<std::packaged_task<int()>>(std::bind(test2, 1, 2));
    std::future<int> res2 = task2->get_future();
    pool.enqueue([&]{(*task2)();});

    pool.enqueue([](){
        std::cout << "hello world second\n";
    });

    std::cout << "res: " << res.get() << "\tres2: " << res2.get() << std::endl;


    sleep(2);

    return 0;
}
